package com.appwoo.txtws.scroll;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.ViewGroup;
import android.widget.Scroller;
import com.appwoo.txtws.component.Logger;

public class MyScrollLayout extends ViewGroup
{
  private static final int SNAP_VELOCITY = 600;
  private static final String TAG = "ScrollLayout";
  private int mCurScreen;
  private int mDefaultScreen = 0;
  private float mLastMotionX;
  private OnViewChangeListener mOnViewChangeListener;
  private Scroller mScroller;
  private VelocityTracker mVelocityTracker;

  public MyScrollLayout(Context paramContext)
  {
    super(paramContext);
    init(paramContext);
  }

  public MyScrollLayout(Context paramContext, AttributeSet paramAttributeSet)
  {
    super(paramContext, paramAttributeSet);
    init(paramContext);
  }

  public MyScrollLayout(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
  {
    super(paramContext, paramAttributeSet, paramInt);
    init(paramContext);
  }

  private boolean IsCanMove(int paramInt)
  {
    if ((getScrollX() <= 0) && (paramInt < 0));
    while ((getScrollX() >= (-1 + getChildCount()) * getWidth()) && (paramInt > 0))
      return false;
    return true;
  }

  private void init(Context paramContext)
  {
    this.mCurScreen = this.mDefaultScreen;
    this.mScroller = new Scroller(paramContext);
  }

  public void SetOnViewChangeListener(OnViewChangeListener paramOnViewChangeListener)
  {
    this.mOnViewChangeListener = paramOnViewChangeListener;
  }

  public void computeScroll()
  {
    if (this.mScroller.computeScrollOffset())
    {
      scrollTo(this.mScroller.getCurrX(), this.mScroller.getCurrY());
      postInvalidate();
    }
  }

  protected void onLayout(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
  {
    int i;
    int j;
    if (paramBoolean)
    {
      i = 0;
      j = getChildCount();
    }
    for (int k = 0; ; k++)
    {
      if (k >= j)
        return;
      View localView = getChildAt(k);
      if (localView.getVisibility() != 8)
      {
        int m = localView.getMeasuredWidth();
        localView.layout(i, 0, i + m, localView.getMeasuredHeight());
        i += m;
      }
    }
  }

  protected void onMeasure(int paramInt1, int paramInt2)
  {
    super.onMeasure(paramInt1, paramInt2);
    int i = View.MeasureSpec.getSize(paramInt1);
    View.MeasureSpec.getMode(paramInt1);
    int j = getChildCount();
    for (int k = 0; ; k++)
    {
      if (k >= j)
      {
        scrollTo(i * this.mCurScreen, 0);
        return;
      }
      getChildAt(k).measure(paramInt1, paramInt2);
    }
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    int i = paramMotionEvent.getAction();
    float f = paramMotionEvent.getX();
    paramMotionEvent.getY();
    switch (i)
    {
    default:
    case 0:
    case 2:
    case 1:
    }
    label290: 
    while (true)
    {
      return true;
      Logger.i("", "onTouchEvent  ACTION_DOWN");
      if (this.mVelocityTracker == null)
      {
        this.mVelocityTracker = VelocityTracker.obtain();
        this.mVelocityTracker.addMovement(paramMotionEvent);
      }
      if (!this.mScroller.isFinished())
        this.mScroller.abortAnimation();
      this.mLastMotionX = f;
      continue;
      int k = (int)(this.mLastMotionX - f);
      if (IsCanMove(k))
      {
        if (this.mVelocityTracker != null)
          this.mVelocityTracker.addMovement(paramMotionEvent);
        this.mLastMotionX = f;
        scrollBy(k, 0);
        continue;
        VelocityTracker localVelocityTracker = this.mVelocityTracker;
        int j = 0;
        if (localVelocityTracker != null)
        {
          this.mVelocityTracker.addMovement(paramMotionEvent);
          this.mVelocityTracker.computeCurrentVelocity(1000);
          j = (int)this.mVelocityTracker.getXVelocity();
        }
        if ((j > 600) && (this.mCurScreen > 0))
        {
          Logger.e("ScrollLayout", "snap left");
          snapToScreen(-1 + this.mCurScreen);
        }
        while (true)
        {
          if (this.mVelocityTracker == null)
            break label290;
          this.mVelocityTracker.recycle();
          this.mVelocityTracker = null;
          break;
          if ((j < -600) && (this.mCurScreen < -1 + getChildCount()))
          {
            Logger.e("ScrollLayout", "snap right");
            snapToScreen(1 + this.mCurScreen);
          }
          else
          {
            snapToDestination();
          }
        }
      }
    }
  }

  public void snapToDestination()
  {
    int i = getWidth();
    snapToScreen((getScrollX() + i / 2) / i);
  }

  public void snapToScreen(int paramInt)
  {
    int i = Math.max(0, Math.min(paramInt, -1 + getChildCount()));
    if (getScrollX() != i * getWidth())
    {
      int j = i * getWidth() - getScrollX();
      this.mScroller.startScroll(getScrollX(), 0, j, 0, 2 * Math.abs(j));
      this.mCurScreen = i;
      invalidate();
      if (this.mOnViewChangeListener != null)
        this.mOnViewChangeListener.OnViewChange(this.mCurScreen);
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.scroll.MyScrollLayout
 * JD-Core Version:    0.6.2
 */